<template>
  <div style="margin-top: 20px; margin: 50px; margin-right: 100px">
    <br />
    <!-- 数据表格 -->
    <template>
      <el-table
        highlight-current-row
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        border
      >

        <el-table-column
          prop="student"
          label="申请人"
          header-align="center"
          align="center"
        ></el-table-column>

        <el-table-column
          prop="deptName"
          label="奖学金名称"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="teacher"
          label="审核老师"
          header-align="center"
          align="center"
        ></el-table-column>

          <el-table-column
          prop="score"
          label="分数"
          header-align="center"
          align="center"
        ></el-table-column>

        <el-table-column
          label="最后操作时间"
          header-align="center"
          align="center"
          width="200"
        >
          <template slot-scope="scope">
            {{
              scope.row.updateTime ? scope.row.updateTime.replace("T", " ") : ""
            }}
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          width="220"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              size=44
              type="primary"
              plain
              @click="selectById(scope.row.id)"
              >打分</el-button
            >

          </template>
        </el-table-column>
      </el-table>
    </template>



    <!-- 编辑对话框 -->

    <el-dialog title="编辑论文" :visible.sync="dialogFormVisible1">
      <el-form :model="job">

       <el-form-item label="分数" :label-width="formLabelWidth">
          <el-input
            v-model="job.score"
            placeholder="请输入分数"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="审核老师" :label-width="formLabelWidth">
          <el-select
            v-model="job.teacher"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="item in empList"
              :key="item.value"
              :label="item.name"
              :value="item.name"
            />
          </el-select>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible1 = false">取 消</el-button>
        <el-button type="primary" @click="add()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>




<script>
import { findAlljob, add, update, deleteById, selectById } from "@/api/lesson.js";
import { findAllemp } from "@/api/person.js";
export default {
  data() {
    return {
      empList: [],
      gradeList: [
        { id: 1, name: "高级" },
        { id: 2, name: "副高级" },
        { id: 3, name: "中级" },
        { id: 4, name: "初级" },
        { id: 5, name: "办事员" },
      ],
      formLabelWidth: "120px",
      dialogFormVisible: false, //控制对话框是否可见
      dialogFormVisible1: false, //控制对话框是否可见
      job: {
        name: "",
        grade: "",
      },
      tableData: [],
    };
  },

  methods: {
    //删除
    deleteById(id) {
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteById(id).then((result) => {
            if (result.data.code == 1) {
              this.$message({
                message: "恭喜你，删除成功",
                type: "success",
              });
            } else {
              this.$message.error(result.data.msg);
            }
            //重新查询数据
            this.init();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    //根据ID查询 -- 回显
    selectById(id) {
      this.dialogFormVisible1 = true;
      selectById(id).then((result) => {
        this.job = result.data.data;
      });
    },

    //保存方法
    add() {
      let method; // 添加
      if (this.job.id) {
        method = update(this.job); // 修改
        method.then((result) => {
          if (result.data.code == 1) {
            //修改成功
            this.$message.success("恭喜你，修改成功");
            //重新查询数据
            this.init();
          } else {
            this.$message.error(result.data.msg);
          }
        });
        // 关闭新建窗口
        this.dialogFormVisible1 = false;

        // 清空模型数据
        this.job = {};
      } else {
        method = add(this.job); //添加
        method.then((result) => {
          if (result.data.code == 1) {
            //修改成功
            this.$message.success("恭喜你，新增成功");
            //重新查询数据
            this.init();
          } else {
            this.$message.error(result.data.msg);
          }
        });
        // 关闭新建窗口
        this.dialogFormVisible = false;

        // 清空模型数据
        this.job = {};
      }
    },

    //初始化 - 查询全部
    init() {
      findAlljob().then((result) => {
        console.log(result);
        if (result.data.code == 1) {
          this.tableData = result.data.data;
        }
      });
    },
  },
  mounted() {
    //当页面加载完成后自动执行。
    this.init();
    findAllemp().then((result) => {
      this.empList = result.data.data;
    });
  },
};
</script>
<style>
</style>
